package com.bruce.codeFactory.Thread.Volatile;

/**
 * @author luotuan
 * @Description
 * @create 2019-02-25 21:49
 **/
public class VolatileSync {
    private volatile static int INIT_VALUE = 0;
    private final static int MAX_LIMIT = 50;

    public static void main(String[] args) {
        new Thread(() -> {
            while (INIT_VALUE < MAX_LIMIT) {
                System.out.printf("Update the value to [%d]\n", ++INIT_VALUE);
            }
        }, "WRITE1").start();
        new Thread(() -> {
            while (INIT_VALUE < MAX_LIMIT) {
                System.out.printf("Update the value to [%d]\n", ++INIT_VALUE);
            }
        }, "WRITE2").start();
    }
}
